package cc.idoone.spring_boot_hello.springsession;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author hemj
 * @since 2017/10/17
 */
@RestController
@RequestMapping("/session")
public class SessionController {

	@RequestMapping("/put")
	public String put(HttpSession session,
					  @RequestParam("key") String key,
					  @RequestParam("value") String value) {
		session.setAttribute(key, value);
		return "PUT OK";
	}

	@RequestMapping("/get")
	public String get(HttpSession session,
					  @RequestParam("key") String key) {
		String value = (String) session.getAttribute(key);

		if (value == null || "".equals(value)) {
			return "NO VALUE GET";
		}
		return value;
	}
}
